<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>处理</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-size:cover;
            background-position: center;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }
#select,
#container {
    display: block;
    width: auto; /* 使其占据父容器的整个宽度 */
    text-align: center; /* 让内容居中对齐 */
    background-color: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    margin: 0 auto; /* 添加垂直间距 */
}
        label {
            font-size: 18px;
            margin-right: 10px;
        }

        input {
            font-size: 16px;
            padding: 8px;
            margin-right: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        button {
            font-size: 16px;
            padding: 10px 20px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body style="">

<div id="wrapper" style="display: flex; flex-direction: column;" >
    <div id="select" style="margin-bottom: 10px;">
        <label for="existingDataInput">企业经营提取已有数据：</label>

        <input type="text" id="existingDataInput" placeholder="EPBH">
        <input type="text" id="JZRQ" placeholder="JZRQ">
        <button type="button" onclick="extractData()">提取数据</button>

    </div>

    <div id="select" style="margin-bottom: 10px;">
        <label for="existingDataInput_HT">华泰提取已有数据：</label>
        <input type="text" id="existingDataInput_HT" placeholder="EPBH">
        <input type="text" id="ht_JZRQ" placeholder="JZRQ">
        <input type="text" id="ZBFL" placeholder="ZBFL">
        <button type="button" onclick="extractData_HT()">提取数据</button>
    </div>

    <div id="select" style="margin-bottom: 10px;">

        <label for="existingDataInput_MX">企业经营明细表提取已有数据：</label>
        <input type="text" id="existingDataInput_MX" placeholder="EPBH">
        <input type="text" id="MX_JZRQ" placeholder="JZRQ">
        <button type="button" onclick="extractData_MX()">提取数据</button>
    </div>

        <div id="select" style="margin-bottom: 10px;">
        <label for="existingDataInput_JRFB">金融分部提取已有数据：</label>
        <input type="text" id="existingDataInput_JRFB" placeholder="EPBH">
        <input type="text" id="JRFB_JZRQ" placeholder="JZRQ">
        <button type="button" onclick="extractData_JRFB()">提取数据</button>
    </div>

    <div id="select" style="margin-bottom: 10px;">
        <label for="existingDataInput_CBFX">成本分析提取已有数据：</label>
        <input type="text" id="existingDataInput_CBFX" placeholder="IGSDM">
        <button type="button" onclick="extractData_CBFX('ykfhs')">提取数据</button>
    </div>
        <div id="container" style="margin-bottom: 10px;">
        <label for="folderNameInput">企业经营数据</label>
        <input type="radio" id="separatedRadio" name="processType" value="ykfhs" checked>
        <label for="separatedRadio">分ID生成</label>
        <input type="radio" id="integratedRadio" name="processType" value="integrated">
        <label for="integratedRadio">整合ID生成</label>
        <label for="folderNameInput">ID：</label>
        <input type="text" id="folderNameInput" placeholder="输入文件夹名称">
        <button type="button" onclick="startProcess()">处理</button>
        <div id="statusMessage"></div>
        <div id="progressMessage"></div>
        </div>


        <div id="container" style="margin-bottom: 10px;">
        <label for="folderNameInput2">成本分析数据</label>
        <input type="radio" id="separatedRadio2" name="processType2" value="ykfhs" checked>
        <label for="separatedRadio2">分ID生成</label>
        <input type="radio" id="integratedRadio2" name="processType2" value="integrated">
        <label for="integratedRadio2">整合ID生成</label>
        <label for="folderNameInput2">ID：</label>
        <input type="text" id="folderNameInput2" placeholder="输入文件夹名称">
        <button type="button" onclick="startProcess_cbfxb('ykfhs')">处理</button>
        <div id="statusMessage"></div>
        </div>
</div>
<div id="hiddenContainer" style="display: none;"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.3.1/socket.io.js"></script>

<script>
    var socket = io.connect('http://' + document.domain + ':' + location.port + '/ykfyyds');
    socket.on('my_response', function(data) {
    // 更新处理进度信息
    var progressMessage = document.getElementById('statusMessage');
    progressMessage.innerText = data.data;
});
function startProcess(processType) {
    var folderName = document.getElementById('folderNameInput').value;
    var statusMessage = document.getElementById('statusMessage');
    var prcessType;
    if (document.getElementById('separatedRadio').checked){
        processType=document.getElementById('separatedRadio').value;
    }else if (document.getElementById('integratedRadio').checked){
        processType
        =document.getElementById('integratedRadio').value;
    }
    var xhr = new XMLHttpRequest();

    xhr.open("POST", "/ykfyyds", true);
    xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
    xhr.responseType = 'blob';
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                // Processing completed successfully
                var blob = xhr.response;
                var url = window.URL.createObjectURL(blob);
                var a = document.createElement('a');
                a.href = url;
                a.download = xhr.getResponseHeader('Content-Disposition').split('filename=')[1];
                a.click();
                window.URL.revokeObjectURL(url);
                statusMessage.innerText = '处理完成';
            } else if (xhr.status === 401) {
                // Processing failed
                statusMessage.innerText = '无表格';
            } else if (xhr.status === 404) {
                // Processing failed
                statusMessage.innerText = '处理失败';
            }
        }
    };
    xhr.send(JSON.stringify({ folderName: folderName, processType: processType,zt:0}));
}

function startProcess_cbfxb() {
    var folderName = document.getElementById('folderNameInput2').value;
    var statusMessage = document.getElementById('statusMessage');
    var processType;

    // 获取选中的单选按钮的值
    if (document.getElementById('separatedRadio2').checked) {
        processType = document.getElementById('separatedRadio2').value;
    } else if (document.getElementById('integratedRadio2').checked) {
        processType = document.getElementById('integratedRadio2').value;
    }

    var xhr = new XMLHttpRequest();
    xhr.open("POST", "/ykfyyds", true);
    xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
    xhr.responseType = 'blob';

    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                // Processing completed successfully
                var blob = xhr.response;
                var url = window.URL.createObjectURL(blob);
                var a = document.createElement('a');
                a.href = url;
                a.download = xhr.getResponseHeader('Content-Disposition').split('filename=')[1];
                a.click();
                window.URL.revokeObjectURL(url);
                statusMessage.innerText = '处理完成';
            } else if (xhr.status === 401) {
                // Processing failed
                statusMessage.innerText = '无表格';
            } else if (xhr.status === 404) {
                // Processing failed
                statusMessage.innerText = '处理失败';
            }
        }
    };
    xhr.send(JSON.stringify({ folderName: folderName, processType: processType, zt: 1 }));
}

function extractData() {
    var existingData = document.getElementById('existingDataInput').value
    var JZRQ=document.getElementById('JZRQ').value;
    var requestData = {
        existingData: existingData,
        JZRQ: JZRQ
    };

    // 发送 POST 请求
    fetch('/jysj', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(requestData)
    })
    .then(response => response.blob()) // 转换为 Blob 对象
    .then(blob => {
        // 创建一个下载链接
        var currentDate = new Date();
        var day = currentDate.getDate();
        var month = currentDate.getMonth() + 1; // getMonth() 返回的月份是从 0 开始的
        var year = currentDate.getFullYear();
        var formattedDate = year + '-' + month + '-' + day;
        var url = window.URL.createObjectURL(blob);
        var a = document.createElement('a');
        a.href = url;
        a.download = formattedDate+'.xlsx'; // 设置下载的文件名
        // 触发下载
        document.body.appendChild(a);
        a.click();
        // 释放链接对象
        window.URL.revokeObjectURL(url);
    })
    .catch(error => console.error('Error:', error));
}
function extractData_CBFX() {
    var existingData = document.getElementById('existingDataInput_CBFX').value;
    var requestData = {
        reportName: existingData
    };

    // 发送 POST 请求
    fetch('/usrcbfxb', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(requestData)
    })
    .then(response => response.blob()) // 转换为 Blob 对象
    .then(blob => {
        // 创建一个下载链接
        var currentDate = new Date();
        var day = currentDate.getDate();
        var month = currentDate.getMonth() + 1; // getMonth() 返回的月份是从 0 开始的
        var year = currentDate.getFullYear();
        var formattedDate = year + '-' + month + '-' + day;
        var url = window.URL.createObjectURL(blob);
        var a = document.createElement('a');
        a.href = url;
        a.download = '成本分析主表'+formattedDate+'.xlsx'; // 设置下载的文件名
        // 触发下载
        document.body.appendChild(a);
        a.click();
        // 释放链接对象
        window.URL.revokeObjectURL(url);
    })
    .catch(error => console.error('Error:', error));
}
function extractData_HT() {
    var existingData = document.getElementById('existingDataInput_HT').value;
    var JZRQ=document.getElementById('ht_JZRQ').value;
    var ZBFL=document.getElementById('ZBFL').value;
    var requestData = {
        existingData: existingData,
        JZRQ: JZRQ,
        ZBFL: ZBFL
    };

    // 发送 POST 请求
    fetch('/usrht', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(requestData)
    })
    .then(response => response.blob()) // 转换为 Blob 对象
    .then(blob => {
        // 创建一个下载链接
        var currentDate = new Date();
        var day = currentDate.getDate();
        var month = currentDate.getMonth() + 1; // getMonth() 返回的月份是从 0 开始的
        var year = currentDate.getFullYear();
        var formattedDate = year + '-' + month + '-' + day;
        var url = window.URL.createObjectURL(blob);
        var a = document.createElement('a');
        a.href = url;
        a.download = '华泰主表'+formattedDate+'.xlsx'; // 设置下载的文件名
        // 触发下载
        document.body.appendChild(a);
        a.click();
        // 释放链接对象
        window.URL.revokeObjectURL(url);
    })
    .catch(error => console.error('Error:', error));
}
function extractData_MX() {
    var existingData = document.getElementById('existingDataInput_MX').value;
    var JZRQ=document.getElementById('MX_JZRQ').value;
    var requestData = {
        existingData: existingData,
        JZRQ: JZRQ
    };

    // 发送 POST 请求
    fetch('/usrMX', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(requestData)
    })
    .then(response => response.blob()) // 转换为 Blob 对象
    .then(blob => {
        // 创建一个下载链接
        var currentDate = new Date();
        var day = currentDate.getDate();
        var month = currentDate.getMonth() + 1; // getMonth() 返回的月份是从 0 开始的
        var year = currentDate.getFullYear();
        var formattedDate = year + '-' + month + '-' + day;
        var url = window.URL.createObjectURL(blob);
        var a = document.createElement('a');
        a.href = url;
        a.download = '明细表'+formattedDate+'.xlsx'; // 设置下载的文件名
        // 触发下载
        document.body.appendChild(a);
        a.click();
        // 释放链接对象
        window.URL.revokeObjectURL(url);
    })
    .catch(error => console.error('Error:', error));
}
function extractData_JRFB() {
    var existingData = document.getElementById('existingDataInput_JRFB').value;
    var JZRQ=document.getElementById('JRFB_JZRQ').value;
    var requestData = {
        existingData: existingData,
        JZRQ: JZRQ
    };

    // 发送 POST 请求
    fetch('/usrJRFB', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify(requestData)
    })
    .then(response => response.blob()) // 转换为 Blob 对象
    .then(blob => {
        // 创建一个下载链接
        var currentDate = new Date();
        var day = currentDate.getDate();
        var month = currentDate.getMonth() + 1; // getMonth() 返回的月份是从 0 开始的
        var year = currentDate.getFullYear();
        var formattedDate = year + '-' + month + '-' + day;
        var url = window.URL.createObjectURL(blob);
        var a = document.createElement('a');
        a.href = url;
        a.download = '明细表'+formattedDate+'.xlsx'; // 设置下载的文件名
        // 触发下载
        document.body.appendChild(a);
        a.click();
        // 释放链接对象
        window.URL.revokeObjectURL(url);
    })
    .catch(error => console.error('Error:', error));
}
</script>

</body>
</html>
